package com.nkym.wypan.utils;/*
 * @ClassName FileUtils
 * @Desc TODO
 * @Author 19637
 * @Date 2023/6/10 23:37
 * @Version 1.0
 */

import com.nkym.wypan.enums.FileType;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class FileUtils {


    public static String getSuffix(String filename) {
        int index = filename.lastIndexOf(".");
        if (index == -1) {
            return "";
        }
        return filename.substring(index + 1, filename.length());
    }

    public static FileType getFileTypeBySuffix(String suffix) {
        List<FileType> list = Arrays.stream(FileType.values())
                .filter(r -> r.getSuffix().equals(suffix))
                .collect(Collectors.toList());
        if (list.size() == 0) {
            return FileType.OTHER;
        }
        return list.get(0);
    }

}
